<template>
	<view class="container">
		<view class="container">
			<uni-easyinput v-model="data.telephone" placeholder="请输入账号"></uni-easyinput>
			<uni-easyinput v-model="data.password" placeholder="请输入密码" style="margin-top: 50rpx;" type="password">
			</uni-easyinput>
			<button type="primary" @click="reg" style="margin-top: 50rpx;">注册</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {
					"telephone": "",
					"password": ""
				}
			}
		},
		methods: {
			reg() {
				uni.request({
					url: 'http://localhost:8090/foodapp/user/register',
					method: 'POST',
					data: this.data,
					success: res => {
						if (res.data.success) {
							uni.switchTab({
								url:'/pages/my/my'
							})
							uni.showToast({
								icon:'none',
								title: '注册成功'
							});
						} else{
							uni.showToast({
								icon:'none',
								title: '用户已存在'
							});
						}
						
					},
					fail: () => {
						uni.showToast({
							icon:'none',
							title: '失败'
						});
					},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
